﻿using System.Windows;
using System.Windows.Controls;
using Brjnk.GpxExplorer.Workspace.Searching;

namespace Brjnk.GpxExplorer.UI
{
    /// <summary>
    /// Interaction logic for SearchConfigurationWindow.xaml
    /// </summary>
    public partial class SearchConfigurationWindow : Window
    {
        private SearchService service;

        public SearchConfigurationWindow(SearchService service)
        {
            this.service = service;

            InitializeComponent();

            editor1.Limit = service.Configuration.MaxWaypointDistance;
            editor1.SearchAgainLimit = service.Configuration.SearchAgainWaypointDistance;
            editor1.SearchInGaps = service.Configuration.SearchWaypointsInPathGaps;

            editor2.Limit = service.Configuration.MaxPhotoDistance;
            editor2.SearchAgainLimit = service.Configuration.SearchAgainPhotoDistance;
            editor2.SearchInGaps = service.Configuration.SearchPhotosInPathGaps;

            editor3.Limit = service.Configuration.MaxPushpinDistance;
            editor3.SearchAgainLimit = service.Configuration.SearchAgainPushpinDistance;
            editor3.SearchInGaps = service.Configuration.SearchPushpinsInPathGaps;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            if (Validation.GetHasError(editor1) || Validation.GetHasError(editor2)) return;
            var config = new SearchConfiguration();
            config.MaxWaypointDistance = editor1.Limit;
            config.SearchAgainWaypointDistance = editor1.SearchAgainLimit;
            config.SearchWaypointsInPathGaps = editor1.SearchInGaps;

            config.MaxPhotoDistance = editor2.Limit;
            config.SearchAgainPhotoDistance = editor2.SearchAgainLimit;
            config.SearchPhotosInPathGaps = editor2.SearchInGaps;

            config.MaxPushpinDistance = editor3.Limit;
            config.SearchAgainPushpinDistance = editor3.SearchAgainLimit;
            config.SearchPushpinsInPathGaps = editor3.SearchInGaps;

            service.Configuration = config;

            this.DialogResult = true;
        }
    }
}